﻿Imports System.Runtime.InteropServices
Imports System.Text

<Flags()> _
    Public Enum IFILTER_INIT As UInteger
    NONE = 0
    CANON_PARAGRAPHS = 1
    HARD_LINE_BREAKS = 2
    CANON_HYPHENS = 4
    CANON_SPACES = 8
    APPLY_INDEX_ATTRIBUTES = 16
    APPLY_CRAWL_ATTRIBUTES = 256
    APPLY_OTHER_ATTRIBUTES = 32
    INDEXING_ONLY = 64
    SEARCH_LINKS = 128
    FILTER_OWNED_VALUE_OK = 512
End Enum

Public Enum CHUNK_BREAKTYPE
    CHUNK_NO_BREAK = 0
    CHUNK_EOW = 1
    CHUNK_EOS = 2
    CHUNK_EOP = 3
    CHUNK_EOC = 4
End Enum

<Flags()> _
Public Enum CHUNKSTATE
    CHUNK_TEXT = &H1
    CHUNK_VALUE = &H2
    CHUNK_FILTER_OWNED_VALUE = &H4
End Enum

<StructLayout(LayoutKind.Sequential)> _
Public Structure PROPSPEC
    Public ulKind As UInteger
    Public propid As UInteger
    Public lpwstr As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public Structure FULLPROPSPEC
    Public guidPropSet As Guid
    Public psProperty As PROPSPEC
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public Structure STAT_CHUNK
    Public idChunk As UInteger
    <MarshalAs(UnmanagedType.U4)> _
    Public breakType As CHUNK_BREAKTYPE
    <MarshalAs(UnmanagedType.U4)> _
    Public flags As CHUNKSTATE
    Public locale As UInteger
    <MarshalAs(UnmanagedType.Struct)> _
    Public attribute As FULLPROPSPEC
    Public idChunkSource As UInteger
    Public cwcStartSource As UInteger
    Public cwcLenSource As UInteger
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public Structure FILTERREGION
    Public idChunk As UInteger
    Public cwcStart As UInteger
    Public cwcExtent As UInteger
End Structure

<ComImport()> _
<Guid("89BCB740-6119-101A-BCB7-00DD010655AF")> _
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IFilter
    Sub Init(<MarshalAs(UnmanagedType.U4)> ByVal grfFlags As IFILTER_INIT, ByVal cAttributes As UInteger, <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)> ByVal aAttributes As FULLPROPSPEC(), ByRef pdwFlags As UInteger)
    <PreserveSig()> _
    Function GetChunk(ByRef pStat As STAT_CHUNK) As Integer
    <PreserveSig()> _
    Function GetText(ByRef pcwcBuffer As UInteger, <MarshalAs(UnmanagedType.LPWStr)> ByVal buffer As StringBuilder) As Integer
    Sub GetValue(ByRef ppPropValue As UIntPtr)
    Sub BindRegion(<MarshalAs(UnmanagedType.Struct)> ByVal origPos As FILTERREGION, ByRef riid As Guid, ByRef ppunk As UIntPtr)
End Interface

<ComImport()> _
<Guid("f07f3920-7b8c-11cf-9be8-00aa004b9986")> _
Public Class CFilter
End Class

Public Class Constants
    Public Const PID_STG_DIRECTORY As UInteger = &H2
    Public Const PID_STG_CLASSID As UInteger = &H3
    Public Const PID_STG_STORAGETYPE As UInteger = &H4
    Public Const PID_STG_VOLUME_ID As UInteger = &H5
    Public Const PID_STG_PARENT_WORKID As UInteger = &H6
    Public Const PID_STG_SECONDARYSTORE As UInteger = &H7
    Public Const PID_STG_FILEINDEX As UInteger = &H8
    Public Const PID_STG_LASTCHANGEUSN As UInteger = &H9
    Public Const PID_STG_NAME As UInteger = &HA
    Public Const PID_STG_PATH As UInteger = &HB
    Public Const PID_STG_SIZE As UInteger = &HC
    Public Const PID_STG_ATTRIBUTES As UInteger = &HD
    Public Const PID_STG_WRITETIME As UInteger = &HE
    Public Const PID_STG_CREATETIME As UInteger = &HF
    Public Const PID_STG_ACCESSTIME As UInteger = &H10
    Public Const PID_STG_CHANGETIME As UInteger = &H11
    Public Const PID_STG_CONTENTS As UInteger = &H13
    Public Const PID_STG_SHORTNAME As UInteger = &H14
    Public Const FILTER_E_END_OF_CHUNKS As Integer = (CInt(&H80041700))
    Public Const FILTER_E_NO_MORE_TEXT As Integer = (CInt(&H80041701))
    Public Const FILTER_E_NO_MORE_VALUES As Integer = (CInt(&H80041702))
    Public Const FILTER_E_NO_TEXT As Integer = (CInt(&H80041705))
    Public Const FILTER_E_NO_VALUES As Integer = (CInt(&H80041706))
    Public Const FILTER_S_LAST_TEXT As Integer = (CInt(&H41709))
End Class

Public Enum IFilterReturnCodes As UInteger

    S_OK = 0
    E_ACCESSDENIED = &H80070005UI
    E_HANDLE = &H80070006UI
    E_INVALIDARG = &H80070057UI
    E_OUTOFMEMORY = &H8007000EUI
    E_NOTIMPL = &H80004001UI
    E_FAIL = &H80000008UI
    FILTER_E_PASSWORD = &H8004170BUI
    FILTER_E_UNKNOWNFORMAT = &H8004170CUI
    FILTER_E_NO_TEXT = &H80041705UI
    FILTER_E_END_OF_CHUNKS = &H80041700UI
    FILTER_E_NO_MORE_TEXT = &H80041701UI
    FILTER_E_NO_MORE_VALUES = &H80041702UI
    FILTER_E_ACCESS = &H80041703UI
    FILTER_W_MONIKER_CLIPPED = &H41704
    FILTER_E_EMBEDDING_UNAVAILABLE = &H80041707UI
    FILTER_E_LINK_UNAVAILABLE = &H80041708UI
    FILTER_S_LAST_TEXT = &H41709
    FILTER_S_LAST_VALUES = &H4170A
End Enum
